home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.basic;
-
- import com.sun.java.swing.DefaultDesktopManager;
- import com.sun.java.swing.DesktopManager;
- import com.sun.java.swing.Icon;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JInternalFrame;
- import com.sun.java.swing.LookAndFeel;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.InternalFrameUI;
- import com.sun.java.swing.plaf.UIResource;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Cursor;
- import java.awt.Dimension;
- import java.awt.IllegalComponentStateException;
- import java.awt.Insets;
- import java.awt.LayoutManager;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.beans.PropertyChangeEvent;
- import java.beans.PropertyChangeListener;
- import java.io.Serializable;
- import java.util.EventListener;
- import java.util.EventObject;
-
- public class BasicInternalFrameUI extends InternalFrameUI implements LayoutManager, PropertyChangeListener, Serializable, MouseListener {
- protected JInternalFrame frame;
- protected EventListener borderListener;
- protected JComponent northPane;
- protected JComponent southPane;
- protected JComponent westPane;
- protected JComponent eastPane;
- protected static DesktopManager sharedDesktopManager;
-
- public BasicInternalFrameUI(JInternalFrame b) {
- }
-
- protected void activateFrame(JInternalFrame f) {
- this.getDesktopManager().activateFrame(f);
- }
-
- public void addLayoutComponent(String name, Component c) {
- }
-
- protected void closeFrame(JInternalFrame f) {
- this.getDesktopManager().closeFrame(f);
- }
-
- protected EventListener createBorderListener(JInternalFrame w) {
- return new BorderListener(this);
- }
-
- protected JComponent createEastPane(JInternalFrame w) {
- return null;
- }
-
- protected JComponent createNorthPane(JInternalFrame w) {
- return new BasicInternalFrameTitlePane(w);
- }
-
- protected JComponent createSouthPane(JInternalFrame w) {
- return null;
- }
-
- public static ComponentUI createUI(JComponent b) {
- return new BasicInternalFrameUI((JInternalFrame)b);
- }
-
- protected JComponent createWestPane(JInternalFrame w) {
- return null;
- }
-
- protected void deactivateFrame(JInternalFrame f) {
- this.getDesktopManager().deactivateFrame(f);
- }
-
- protected void deiconifyFrame(JInternalFrame f) {
- this.getDesktopManager().deiconifyFrame(f);
- }
-
- protected void deinstallMouseHandlers(JComponent c) {
- if (c != null) {
- if (this.borderListener instanceof MouseListener) {
- ((Component)c).removeMouseListener((MouseListener)this.borderListener);
- }
-
- if (this.borderListener instanceof MouseMotionListener) {
- ((Component)c).removeMouseMotionListener((MouseMotionListener)this.borderListener);
- }
- }
-
- }
-
- protected DesktopManager getDesktopManager() {
- if (this.frame.getDesktopPane() != null && this.frame.getDesktopPane().getDesktopManager() != null) {
- return this.frame.getDesktopPane().getDesktopManager();
- } else {
- if (sharedDesktopManager == null) {
- sharedDesktopManager = new DefaultDesktopManager();
- }
-
- return sharedDesktopManager;
- }
- }
-
- public JComponent getEastPane() {
- return this.eastPane;
- }
-
- public Dimension getMaximumSize(JComponent x) {
- return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
- }
-
- public Dimension getMinimumSize(JComponent x) {
- return this.frame == x ? this.frame.getLayout().minimumLayoutSize(x) : new Dimension(0, 0);
- }
-
- public JComponent getNorthPane() {
- return this.northPane;
- }
-
- public Dimension getPreferredSize(JComponent x) {
- return this.frame == x ? this.frame.getLayout().preferredLayoutSize(x) : new Dimension(100, 100);
- }
-
- public JComponent getSouthPane() {
- return this.southPane;
- }
-
- public JComponent getWestPane() {
- return this.westPane;
- }
-
- protected void iconifyFrame(JInternalFrame f) {
- this.getDesktopManager().iconifyFrame(f);
- }
-
- protected void installDefaults(JInternalFrame frame) {
- Icon frameIcon = frame.getFrameIcon();
- if (frameIcon == null || frameIcon instanceof UIResource) {
- frame.setFrameIcon(UIManager.getIcon("InternalFrame.icon"));
- }
-
- LookAndFeel.installBorder(frame, "InternalFrame.border");
- }
-
- protected void installMouseHandlers(JComponent c) {
- if (c != null) {
- if (this.borderListener instanceof MouseListener) {
- ((Component)c).addMouseListener((MouseListener)this.borderListener);
- }
-
- if (this.borderListener instanceof MouseMotionListener) {
- ((Component)c).addMouseMotionListener((MouseMotionListener)this.borderListener);
- }
- }
-
- }
-
- public void installUI(JComponent c) {
- this.frame = (JInternalFrame)c;
- this.frame.add(this.frame.getRootPane(), "Center");
- this.installDefaults(this.frame);
- this.borderListener = this.createBorderListener(this.frame);
- this.frame.addPropertyChangeListener(this);
- this.frame.setLayout(this);
- this.setNorthPane(this.createNorthPane(this.frame));
- this.setSouthPane(this.createSouthPane(this.frame));
- this.setEastPane(this.createEastPane(this.frame));
- this.setWestPane(this.createWestPane(this.frame));
- this.installMouseHandlers(this.frame);
- this.frame.setOpaque(true);
- this.frame.setMinimumSize(new Dimension(120, 24));
- }
-
- public void layoutContainer(Container c) {
- Insets i = this.frame.getInsets();
- int cx = i.left;
- int cy = i.top;
- int cw = this.frame.getWidth() - i.left - i.right;
- int ch = this.frame.getHeight() - i.top - i.bottom;
- if (this.getNorthPane() != null) {
- Dimension size = this.getNorthPane().getPreferredSize();
- this.getNorthPane().setBounds(cx, cy, cw, size.height);
- cy += size.height;
- ch -= size.height;
- }
-
- if (this.getSouthPane() != null) {
- Dimension size = this.getSouthPane().getPreferredSize();
- this.getSouthPane().setBounds(cx, this.frame.getHeight() - i.bottom - size.height, cw, size.height);
- ch -= size.height;
- }
-
- if (this.getWestPane() != null) {
- Dimension size = this.getWestPane().getPreferredSize();
- this.getWestPane().setBounds(cx, cy, size.width, ch);
- cw -= size.width;
- cx += size.width;
- }
-
- if (this.getEastPane() != null) {
- Dimension size = this.getEastPane().getPreferredSize();
- this.getEastPane().setBounds(cw - size.width, cy, size.width, ch);
- cw -= size.width;
- }
-
- if (this.frame.getRootPane() != null) {
- this.frame.getRootPane().setBounds(cx, cy, cw, ch);
- }
-
- }
-
- protected void maximizeFrame(JInternalFrame f) {
- this.getDesktopManager().maximizeFrame(f);
- }
-
- protected void minimizeFrame(JInternalFrame f) {
- this.getDesktopManager().minimizeFrame(f);
- }
-
- public Dimension minimumLayoutSize(Container c) {
- Insets i = this.frame.getInsets();
- Dimension result = this.frame.getRootPane().getMinimumSize();
- result.width += i.left + i.right;
- result.height += i.top + i.bottom;
- if (this.getNorthPane() != null) {
- Dimension d = this.getNorthPane().getMinimumSize();
- result.width = Math.max(d.width, result.width);
- result.height += d.height;
- }
-
- if (this.getSouthPane() != null) {
- Dimension d = this.getSouthPane().getMinimumSize();
- result.width = Math.max(d.width, result.width);
- result.height += d.height;
- }
-
- if (this.getEastPane() != null) {
- Dimension d = this.getEastPane().getMinimumSize();
- result.width += d.width;
- result.height = Math.max(d.height, result.height);
- }
-
- if (this.getWestPane() != null) {
- Dimension d = this.getWestPane().getMinimumSize();
- result.width += d.width;
- result.height = Math.max(d.height, result.height);
- }
-
- return result;
- }
-
- public void mouseClicked(MouseEvent e) {
- }
-
- public void mouseEntered(MouseEvent e) {
- }
-
- public void mouseExited(MouseEvent e) {
- }
-
- public void mousePressed(MouseEvent e) {
- ((BorderListener)this.borderListener).mousePressed(e);
- }
-
- public void mouseReleased(MouseEvent e) {
- }
-
- public Dimension preferredLayoutSize(Container c) {
- Insets i = this.frame.getInsets();
- Dimension result = this.frame.getRootPane().getPreferredSize();
- result.width += i.left + i.right;
- result.height += i.top + i.bottom;
- if (this.getNorthPane() != null) {
- Dimension d = this.getNorthPane().getPreferredSize();
- result.width = Math.max(d.width, result.width);
- result.height += d.height;
- }
-
- if (this.getSouthPane() != null) {
- Dimension d = this.getSouthPane().getPreferredSize();
- result.width = Math.max(d.width, result.width);
- result.height += d.height;
- }
-
- if (this.getEastPane() != null) {
- Dimension d = this.getEastPane().getPreferredSize();
- result.width += d.width;
- result.height = Math.max(d.height, result.height);
- }
-
- if (this.getWestPane() != null) {
- Dimension d = this.getWestPane().getPreferredSize();
- result.width += d.width;
- result.height = Math.max(d.height, result.height);
- }
-
- return result;
- }
-
- public void propertyChange(PropertyChangeEvent evt) {
- String prop = evt.getPropertyName();
- JInternalFrame f = (JInternalFrame)((EventObject)evt).getSource();
- Object newValue = evt.getNewValue();
- Object oldValue = evt.getOldValue();
- if ("rootPane".equals(prop)) {
- if (oldValue != null) {
- this.frame.remove((Component)oldValue);
- }
-
- if (newValue != null) {
- this.frame.add((Component)newValue);
- }
- } else if ("isClosed".equals(prop)) {
- if (newValue == Boolean.TRUE) {
- this.closeFrame(f);
- }
- } else if ("isMaximum".equals(prop)) {
- if (newValue == Boolean.TRUE) {
- this.maximizeFrame(f);
- } else {
- this.minimizeFrame(f);
- }
- } else if ("isIcon".equals(prop)) {
- if (newValue == Boolean.TRUE) {
- this.iconifyFrame(f);
- } else {
- this.deiconifyFrame(f);
- }
- } else if ("isSelected".equals(prop)) {
- if (newValue == Boolean.TRUE && oldValue == Boolean.FALSE) {
- this.activateFrame(f);
- } else if (newValue == Boolean.FALSE && oldValue == Boolean.TRUE) {
- this.deactivateFrame(f);
- }
- }
-
- }
-
- public void removeLayoutComponent(Component c) {
- }
-
- protected void replacePane(JComponent currentPane, JComponent newPane) {
- if (currentPane != null) {
- this.deinstallMouseHandlers(currentPane);
- this.frame.remove(currentPane);
- }
-
- if (newPane != null) {
- this.frame.add(newPane);
- this.installMouseHandlers(newPane);
- }
-
- }
-
- public void setEastPane(JComponent c) {
- this.eastPane = c;
- }
-
- public void setNorthPane(JComponent c) {
- this.replacePane(this.northPane, c);
- this.northPane = c;
- }
-
- public void setSouthPane(JComponent c) {
- this.southPane = c;
- }
-
- public void setWestPane(JComponent c) {
- this.westPane = c;
- }
-
- protected void uninstallDefaults(JInternalFrame frame) {
- Icon frameIcon = frame.getFrameIcon();
- if (frameIcon instanceof UIResource) {
- frame.setFrameIcon((Icon)null);
- }
-
- LookAndFeel.uninstallBorder(frame);
- }
-
- public void uninstallUI(JComponent c) {
- if (c != this.frame) {
- throw new IllegalComponentStateException(this + " was asked to deinstall() " + c + " when it only knows about " + this.frame + ".");
- } else {
- this.uninstallDefaults(this.frame);
- this.frame.setCursor(Cursor.getPredefinedCursor(0));
- this.setNorthPane((JComponent)null);
- this.setSouthPane((JComponent)null);
- this.setEastPane((JComponent)null);
- this.setWestPane((JComponent)null);
- this.frame.setLayout((LayoutManager)null);
- this.deinstallMouseHandlers(this.frame);
- this.borderListener = null;
- this.frame.removePropertyChangeListener(this);
- this.frame.remove(this.frame.getRootPane());
- this.frame = null;
- }
- }
- }
-